import Vue from 'vue'
import Vuex from 'vuex'

import VuexPersistence from 'vuex-persist'
Vue.use(Vuex);
const vuexLocal = new VuexPersistence({
    storage: window.sessionStorage,
    modules: []
});
export default new Vuex.Store({
    modules: {},
    state: {
        token: '',
        username: '',
        hasResRouter: false,
        routers: []
    },
    mutations: {
        setToken(state, data) {
            window.sessionStorage.setItem('api-token', data);
            state.token = data;
        },
        setUsername(state, data) {
            state.username = data;
        },
        setRouters(state, data) {
            state.routers = data;
        }
    },
    actions: {
        generateRouters({commit}, payLoad) {
            //commit('menu/GenerateModuleList', payLoad[0].children);
        }
    },
    plugins: [vuexLocal.plugin]
})
